USE [BDMaraket]
GO
/****** Object:  StoredProcedure [dbo].[GetPagedTransactionDetails]    Script Date: 05/18/2013 22:19:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
-------------------------------------------------------------------------------
--	METADATA AND OTHER MESSAGES ABOVE.
--	BEGIN CREATE STATEMENTS.
-------------------------------------------------------------------------------

ALTER PROCEDURE [dbo].[GetPagedTransactionDetails]	
	@CompanyID AS INT
	, @StartRecord AS INT
	, @EndRecord AS INT
AS
BEGIN	
	SET NOCOUNT ON;    
	WITH InventoryTransaction AS
	(
		SELECT
		TransactionDate AS [DATE]
		,S.[Address] AS [Store]
		,T.ReferenceNo AS [ReferenceNo]
		,T.[Description] AS [Description]
		,ROW_NUMBER() OVER (ORDER BY T.TransactionDate DESC) AS [RowNumber]
		FROM [Transaction] T
		INNER JOIN Store S ON T.StoreID = S.ID
		WHERE S.CompanyID = @CompanyID
	)
	SELECT *		
		, (SELECT MAX(RowNumber) FROM InventoryTransaction) AS TotalRecord
	FROM InventoryTransaction
	WHERE [RowNumber] BETWEEN @StartRecord AND @EndRecord
END
